package com.huey.utils.json;

import com.alibaba.fastjson.serializer.ValueFilter;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Objects;

@Component
public class MyValueFilter implements ValueFilter {
    @Override
    public Object process(Object o, String name, Object value) {
        if (Objects.isNull(value)) {
            return value;
        }
		//o是待转换的对象，name是字段名，value是字段值
        if (value instanceof BigDecimal) {
            DecimalFormat df = new DecimalFormat(",##0.00");
            return df.format(value);
        } else if (value instanceof Long && !"totalElements".equals(name)) {
            return String.valueOf(value);
        }
        return value;
    }
}